﻿using System;
using NHibernate.Dialect;

namespace HYCodeBase.SqlUtility.ORMSuit
{
	public class SqlliteConfigurationPacker : ConfigurationPacker
	{
		public SqlliteConfigurationPacker(string inputDbFileFullName, string inputPassWord = null)
		{
			this.m_useFileName = inputDbFileFullName;
			this.m_usePassWord = inputPassWord;
			this.m_strUseDirverFileName = "System.Data.SQLite.dll";
			this.m_dicUseProperties.Add("connection.driver_class", "NHibernate.Driver.SQLite20Driver");
			this.m_dicUseProperties.Add("dialect", "NHibernate.Dialect.SQLiteDialect");
		}

		protected override string MakeConnectionString()
		{
			string result = string.Empty;
			if (string.IsNullOrWhiteSpace(this.m_usePassWord))
			{
				result = "Data Source = " + this.m_useFileName + ";Version=3";
			}
			else
			{
				result = "Data Source = " + this.m_useFileName + ";Version=3;Password=" + this.m_usePassWord;
			}
			return result;
		}

		internal override Dialect GetUseDialect()
		{
			return new SQLiteDialect();
		}

		private string m_useFileName;
	}
}
